home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c++
- Subject: Re: C++ Gurus! Is it correct?
- Date: Sun, 04 Feb 1996 00:59:16 GMT
- Organization: Netcom
- Message-ID: <311403bf.169980736@nntp.ix.netcom.com>
- References: <4eqvtg$cg5@israel-info.datasrv.co.il> <4etnju$6gn@rolaids.frco.com> <4f0n8s$a3b@news2.ios.com>
- NNTP-Posting-Host: ix-dc15-14.ix.netcom.com
- X-NETCOM-Date: Sat Feb 03 4:58:57 PM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- vlad@gramercy.ios.com (Vlastimil Adamovsky) wrote:
-
- > Jadam@tcmail.frco.com (Jim Adam) wrote:
- >
- > >In article <4eqvtg$cg5@israel-info.datasrv.co.il>, dmitry@enigma.co.il
- > >says...
- >
- > >>Is next code is correct from point of view of pure C++ ?
- >
- > >>class A
- > >>{
- > >>};
- >
- > >>class B
- > >>{
- > >>};
- >
- > >>class C : public A, public B
- > >>{
- > >>};
- >
- > >>A* pA = new C;
- > >>B* pB = new C;
- >
- > >>delete pA;
- > >>delete pB;
- >
- > >==========================
- >
- > >This is correct. However, to ensure the destructor for class
- > >C gets called correctly, class A and B both need virtual
- > >destructors.
- >
- > >E.g.,
- >
- > > class A
- > > {
- > > public:
- > > virtual ~A();
- > > };
- >
- > >And likewise for class B.
- >
- > >Jim
- >
- > I don't think the virtual destructor is necessary in this specific
- > case where you have no added data in subclasses.
-
- Why do you think having data has anything to do with it? From draft
- 5.3.5:
-
- In the first alternative (delete object), if the static type
- of the operand is different from its dynamic type, the static
- type shall be a base class of the operand's dynamic type
- and the static type shall have a virtual destructor or the
- behavior is undefined.
-
-
- Michael M Rubenstein
-